package com.firefly.service.repository.ums;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.firefly.dao.dao.ums.po.AdminPo;
import com.firefly.dao.dao.ums.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @description: 管理员
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/9
 **/
@Repository
public class AdminRepository {
    private final AdminService adminService;
    @Autowired
    public AdminRepository(AdminService adminService){
        this.adminService = adminService;
    }
    public Boolean create(AdminPo entity){
        return adminService.save(entity);
    }
    public Boolean updateInfo(AdminPo entity){
        return adminService.updateById(entity);
    }
    public Boolean updatePwd(int id,String crypt,String pwd){
        UpdateWrapper<AdminPo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.set("crypt", crypt);
        updateWrapper.set("password", pwd);
        return adminService.update(updateWrapper);
    }
    public Boolean updateStatus(int id,int status){
        UpdateWrapper<AdminPo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.set("status", status);
        return adminService.update(updateWrapper);
    }

    public Boolean removeById(int id){
        return adminService.removeById(id);
    }
    public Boolean removeByIds(List<Integer> ids){
        return adminService.removeByIds(ids);
    }

    public void updateLastIpAndTime(int id, String ip, LocalDateTime time){
        UpdateWrapper<AdminPo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.set("lastip", ip);
        updateWrapper.set("lasttime", time);
        adminService.update(updateWrapper);
    }
}
